package com.company.cloud.uba.modules.bus.consumer;

import com.alibaba.fastjson.JSON;
import com.company.cloud.common.constant.ConfigConstants;
import com.company.cloud.common.mq.redis.client.consumer.MQSaasResult;
import com.company.cloud.uba.modules.app.service.UserLogoutLogAppService;
import com.company.common.server.config.mq.constant.MQTopicKeys;
import com.company.common.server.config.mq.models.MQUserLoginModel;
import com.company.common.server.config.mq.models.MQUserLogoutModel;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

@Log4j2
@ConditionalOnProperty(value = ConfigConstants.CONFIG_Active_MQ_ENABLED, havingValue = "true")
@Service
public class UserLogoutActiveConsumer {


    @Autowired
    private UserLogoutLogAppService userLogoutLogAppService;

    @JmsListener(destination = MQTopicKeys.MQ_UserLogout_Topic ,containerFactory = "topicListener")
    public void consume(String message){
        try {

            MQUserLogoutModel entity=JSON.parseObject(message,MQUserLogoutModel.class);
            if(entity!=null){
                userLogoutLogAppService.addUserLogout(entity);
            }
        }catch (Exception e){
            log.debug("+++++用户登出消费者,执行业务错误:",e.getCause());
        }
    }
}
